package com.nasarius.bank.scorecard.web.controller.common;

import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class WelcomeController {
	/**
     * <p>Person form request.</p>
     * 
     * <p>Expected HTTP GET and request '/welcome/view'.</p>
     */
    @RequestMapping(value="/welcome/view", method=RequestMethod.GET)
    public String form() {
		List<GrantedAuthority> authorityList = (List<GrantedAuthority>)SecurityContextHolder.getContext().getAuthentication().getAuthorities();
		GrantedAuthority authority = authorityList.get(0);
		String url=null;
		if("ROLE_ADMIN".equalsIgnoreCase(authority.getAuthority())){
			url = "redirect:/topicdetails/view.html";
		}else if("ROLE_LBU".equalsIgnoreCase(authority.getAuthority()) || "ROLE_CBU".equalsIgnoreCase(authority.getAuthority())){
			url = "redirect:/uploadCSV/select.html";
		}else if("ROLE_SURVEY".equalsIgnoreCase(authority.getAuthority())){
			url = "redirect:/surveyordetails/view.html";
		}
		return url;
    }
}
